﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.IO;
using System.Web.Services;
using System.Net;
using System.Data;

namespace SharePointWebDisplay
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {

                try
                {
                    
                    SharePointList.Lists L = new SharePointList.Lists();
                    L.Url = "http://sp2010-2/_vti_bin/Lists.asmx";

                    L.Credentials = new NetworkCredential("Administrator", "YOUR PASSWORD", "YOUR DOMAIN");

                    System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
                    string listName = "{2B115F16-A802-4492-AE08-5BEEE67B84CC}";
                    string viewName = "Clients";
                    string rowLimit = "1";
                    string strReturn = "";
                    System.Xml.XmlElement ndQuery = xmlDoc.CreateElement("Query");
                    System.Xml.XmlElement ndViewFields = xmlDoc.CreateElement("ViewFields");
                    System.Xml.XmlElement ndQueryOptions = xmlDoc.CreateElement("QueryOptions");

                    ndQuery.InnerXml = "<Where><Eq><FieldRef Name=\"ID\" />" +
                            "<Value Type=\"Counter\">1</Value>" +
                            "</Eq></Where>";
                    ndViewFields.InnerXml = "<FieldRef Name=\"ID\" /><FieldRef Name=\"ClientCode\" />";
                    ndQueryOptions.InnerXml = "";

                    System.Xml.XmlNode nodeListItems = L.GetListItems(listName, null, null, ndViewFields, null, null, null);

                    foreach (System.Xml.XmlNode X in nodeListItems)
                    {
                        strReturn += X.OuterXml;
                    }

                    DataSet ds = new DataSet();
                    using (StringReader stringReader = new StringReader(strReturn))
                    {
                        //initialize our DataSet
                        ds = new DataSet();

                        //load the StringReader to our DataSet
                        ds.ReadXml(stringReader);
                    }

                    GridView1.DataSource = ds.Tables[1];
                    GridView1.DataBind();
                }
                catch (WebException exp)
                {


                    //string s = "WebException  " + exp.Message + " " + exp.StackTrace + " " + exp.Status + " " + exp.Response + " " + exp.Response.Headers + " " + exp.Response.GetResponseStream() + " " + exp.Response.ResponseUri.ToString();
                    Response.Write(exp.Message);
                    Response.Write(exp.StackTrace);
                    Response.Write(exp.Status.ToString());
                    Response.Write(exp.Response.ToString());
                    Response.Write(exp.Response.Headers.ToString());
                    Response.Write(exp.Response.GetResponseStream().ToString());
                    Response.Write(exp.Response.ResponseUri.ToString());

                }
                catch (Exception exp)
                {
                    Response.Write(exp.Message);
                    Response.Write(exp.StackTrace);
                }

            }
        }
    }
}
